package com.lianniu.mgr.supplyManage.service.impl;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.pagination.PaginationInfo;
import com.lianniu.mgr.supplyManage.dao.ISupplyAreaDao;
import com.lianniu.mgr.supplyManage.service.ISupplyAreaService;
import com.lianniu.mgr.supplyManage.vo.SupplyAreaVo;
import com.lianniu.mgr.supplyManage.vo.SupplyConditionVo;
@Service
public class SupplyAreaServiceImpl implements ISupplyAreaService {
    
    private static Logger logger = LoggerFactory.getLogger(SupplyAreaServiceImpl.class);
    
    @Autowired
    ISupplyAreaDao supplyAreaDao;
    @Override
    public BaseResult selectBySupplyAreaForPage(SupplyConditionVo supplyConditionVo,
                    PaginationInfo paginationInfo) {
        supplyConditionVo.setPaginationInfo(paginationInfo);
        logger.info("SupplyAreaServiceImpl begin 获取供应商销售区域列表:"+JSON.toJSONString(supplyConditionVo));
        List<SupplyAreaVo> supplyList = supplyAreaDao.selectBySupplyAreaForPage(supplyConditionVo);
        logger.info("获取到的销售区域列表为："+JSON.toJSONString(supplyList));
        Map<String, Object> retmap = new HashMap<String,Object>();
        retmap.put("total", paginationInfo.getTotalRecord());
        retmap.put("curPage", paginationInfo.getCurPage());
        retmap.put("rows", supplyList);
        return BaseResult.success(retmap);
    }
    @Override
    public BaseResult getAreaName(String areaId) {
       logger.info("getAreaName begin "+areaId);
        return BaseResult.success(supplyAreaDao.getAreaName(areaId));
    }
    @Override
    public BaseResult getSupplyAreaById(String id) {
       logger.info(JSON.toJSONString(id));   
       SupplyAreaVo supplyAreaVo = supplyAreaDao.getSupplyAreaById(id);
        return BaseResult.success(supplyAreaVo);
    }
    @Override
    public BaseResult getSupplyList() {
       logger.info("getSupplyList begin");
       List<SupplyAreaVo> supplyAreaList = supplyAreaDao.getSupplyList();
        return BaseResult.success(supplyAreaList);
    }
    @Override
    public BaseResult insertSupplyArea(SupplyAreaVo supplyAreaVo) {
        logger.info("insertSupplyArea begin");
        int i = supplyAreaDao.insertSupplyArea(supplyAreaVo);
        return BaseResult.success(i);
    }
    @Override
    public BaseResult deleteSupplyArea(SupplyAreaVo supplyAreaVo) {
       logger.info("deleteSupplyArea begin");
       int i = supplyAreaDao.deleteSupplyArea(supplyAreaVo);
        return BaseResult.success(i);
    }
    @Override
    public BaseResult updateById(SupplyAreaVo supplyAreaVo) {
        logger.info("updateById begin");
        int i = supplyAreaDao.updateById(supplyAreaVo);
        return BaseResult.success(i);
    }

}
